import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:speed_random/app_styles.dart';
import 'package:speed_random/common/common_fuc.dart';
import 'package:speed_random/pages/home/rand_com/com_results/view.dart';
import 'package:speed_random/pages/home/rand_com/view_set.dart';
import 'package:speed_random/widgets/row_two_buttons.dart';

import 'logic.dart';
import 'state.dart';


class ViewBodyRoller extends StatelessWidget {

  final RandComLogic logic;
  final RandComState state;

  const ViewBodyRoller({Key? key, required this.logic, required this.state}) : super(key: key);




    // ... 已有代码 ...

@override
Widget build(BuildContext context) {
  final diceNums= {
    '⚀': 1,
    '⚁': 2,
    '⚂': 3,
    '⚃': 4,
    '⚄': 5,
    '⚅': 6,
  };

  var randomNumberssort = [];

  return Obx(() => Card(
    color: state.randComArgs.value.colorPagebg,
    child: Column(
      children: [
        Center( // 添加Center组件确保整体居中
          child: SingleChildScrollView( // 替换ListView为SingleChildScrollView
            padding: EdgeInsets.all(16), // 添加内边距
            child: Wrap(
              alignment: WrapAlignment.center, // 确保Wrap内容居中
              spacing: 5.0,
              runSpacing: 5.0,
              children: state.randomNumbers.map<Widget>((number) {
                // 定义骰子面对应的颜色
                final diceColors = {
                  '⚀': Colors.red,
                  '⚁': Color(0xFF062DBA),
                  '⚂': Color(0xFF062DBA),
                  '⚃': Colors.red,
                  '⚄': Color(0xFF062DBA),
                  '⚅': Color(0xFF062DBA),
                };
                state.randomNumbersSum.value = state.randomNumbers.value.fold(0, (sum, number) => sum + diceNums[number]!??0);
                 randomNumberssort = state.randomNumbers.value.join('').split('').map((e) => diceNums[e]??0).toList();
                randomNumberssort.sort();
                return Container(
                  padding: EdgeInsets.all(5),
                  child: Text(
                    "$number",
                    style: TextStyle(
                      fontSize: 100,
                      fontWeight: FontWeight.bold,
                      color: diceColors[number] ?? state.randComArgs.value.colorPageText, // 使用骰子面颜色，如果没有匹配则使用默认颜色
                    ),
                  ),
                );
              }).toList(),
            ),
          ),
        ),
         Obx(() => Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    '${randomNumberssort}',
                    style: TextStyle(
                      fontSize: 20,
                     // color: state.randComArgs.value.colorPageText,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  SizedBox(width: 10,),
                  Text(
                    '总和'.tr+': ${state.randomNumbersSum.value}',
                    style: TextStyle(
                      fontSize: 20,
                     // color: state.randComArgs.value.colorPageText,
                      fontWeight: FontWeight.bold,
                    ),
                  )
                ],
              ),),
        SizedBox(height: 10,)
      ],
    ),
  ));
}

// ... 已有代码 ...






}


